import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;

public class Login extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6728137952566268615L;
	private JPanel contentPane;
	private JPasswordField passwordField;
	private String password = "test";
	
	int guesses = 0;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Login");
		setBounds(100, 100, 270, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblDpssSystems = new JLabel("DPSS Systems");
		lblDpssSystems.setBounds(94, 27, 96, 14);
		contentPane.add(lblDpssSystems);
		
		JLabel lblUsername = new JLabel("Username");
		lblUsername.setBounds(10, 75, 66, 14);
		contentPane.add(lblUsername);
		
		JLabel lblAdmin = new JLabel("Admin");
		lblAdmin.setBounds(104, 75, 66, 14);
		contentPane.add(lblAdmin);
		
		JLabel lblPassword = new JLabel("Password");
		lblPassword.setBounds(10, 118, 66, 14);
		contentPane.add(lblPassword);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(94, 115, 86, 20);
		contentPane.add(passwordField);
		passwordField.setColumns(10);
		
		JButton btnClose = new JButton("Close");
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnClose.setBounds(25, 228, 89, 23);
		contentPane.add(btnClose);
		
		JButton btnSubmit = new JButton("Submit");
		btnSubmit.setBounds(144, 228, 89, 23);
		contentPane.add(btnSubmit);
		getRootPane().setDefaultButton(btnSubmit);
		btnSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			
				 @SuppressWarnings("deprecation")
				String value1=passwordField.getText(); // Setting a variable for what the user enters into the JTextField
			       
			        
			        if (value1.equals(password))
			        	{
			            JOptionPane.showMessageDialog(null, "Welcome"); // A dialog box will appear Welcoming the user..
			            MainMenu page=new MainMenu(); // Open the next page..
			            page.setVisible(true); // Makes the next page visible
			            dispose();
			        }    
			        else 
			        {
			        	guesses = guesses + 1;
			        	passwordField.setText("");
			        	JOptionPane.showMessageDialog(null, "Incorrect Password");
			        }
			 	
			    if (guesses == 3) { 

			    	JOptionPane.showMessageDialog ( null, "Too many guesses wrong" );
			        passwordField.setEditable(false); 
			    }
			}
		});
	}
}